package com.sound
{
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundLoaderContext;
	import flash.media.SoundTransform;
	import flash.net.URLRequest;
	
	public dynamic class DynamicSound extends Sound
	{
		public var path:String; // 文件路径，url跟nativepath有区别，该属性为了兼容这种区别
		private var _soundChannel:SoundChannel;
		private var _stopPosition:Number; // 上次停止播放的位置
		
		public function DynamicSound(stream:URLRequest=null, context:SoundLoaderContext=null)
		{
			super(stream, context);
		}
		
		public override function play(startTime:Number=0, loops:int=0, sndTransform:SoundTransform=null):SoundChannel{
			_soundChannel = super.play(startTime, loops, sndTransform);
			return _soundChannel;
		}
		
		public function get soundChannel():SoundChannel{
			return _soundChannel;
		}
		
		public function stop():void{
			_stopPosition = _soundChannel.position;
			_soundChannel.stop();
		}
		
		public function get stopPosition():Number{
			return _stopPosition;
		}
		
		public function set stopPosition(value:Number):void{
			if(value >= 0 && value <= length){
				_stopPosition = value;
			}
		}
		
		public function set volume(value:Number):void{
			var stf:SoundTransform = _soundChannel.soundTransform;
			stf.volume = value;
			_soundChannel.soundTransform = stf;
		}
		
		public function get volume():Number{
			return _soundChannel.soundTransform.volume;
		}
	}
}